package com.ruoyi.system.api;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
import com.ruoyi.system.api.model.LoginUser;

import java.util.List;

/**
 * 用户服务
 *
 * @author ruoyi
 */
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService
{
    /**
     * 通过用户名查询用户信息
     *
     * @param username 用户名
     * @param source 请求来源
     * @return 结果
     */
    @GetMapping("/user/info/{username}")
    public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 注册用户信息
     *
     * 4.0.0以后废弃
     */
//    @PostMapping("/user/register")
//    public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 注册系统用户
     * @param sysUser
     * @param source
     * @return
     * @version 4.0.0
     */
    @PostMapping("/user")
    public R<Boolean> registerUser(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 根据id获取用户信息
     * @param userId
     * @return
     */
    @GetMapping("/user/{userId}")
    public R<Object> selectUserById(@PathVariable("userId") Long userId);

    /**
     * 修改用户
     */
    @PutMapping("/user")
    public R<Object> updateUser(@RequestBody SysUser user);

    /**
     * 删除用户
     */
    @DeleteMapping("/{userId}")
    public R<Object> deleteUserById(@PathVariable("userId") Long userId);

    /**
     * 给用户赋角色
     */
    @PutMapping("/user/insertUserRole/{userId}/{roleId}")
    public R<Object> insertUserRole(@PathVariable("userId") Long userId,@PathVariable("roleId") Long roleId,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     *
     */
    @GetMapping("/role/selectUserIdsByRoleId/{roleId}")
    public List<Long> selectUserIdsByRoleId(@PathVariable("roleId") Long roleId);


    /**
     * 给用户赋角色
     */
    @GetMapping("/user/queryRoleByKey/{key}")
    public R<Object> queryRoleByKey(@PathVariable("key")String key);
}
